home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 647 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.5 KB  |  76 lines

  1. Path: chronicle.mti.sgi.com!austern
  2. From: James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Inialization and user-defined conversion
  5. Date: 06 Mar 1996 10:06:23 PST
  6. Organization: -
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <9603061803.AA11656@lts.sel.alcatel.de>
  9. References: <199603051249.PAA00513@boy.nmd.msu.ru>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: Wed, 6 Mar 96 19:03:55 +0100
  12. In-Reply-To: Alexander Krotoff's message of 05 Mar 1996 09:45:02 PST
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMT3UK0y4NqrwXLNJAQGOlAIAztAZ/+9pSaMDt8M7MhtFWNhs+NVKimSR
  15.     z+YLyiWP4WFxWzq5A+sjyqRfWTpn9vjx1HHSf3ZJLelNf+vY7aVDjg==
  16.     =d/Rd
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In article <199603051249.PAA00513@boy.nmd.msu.ru> Alexander Krotoff
  20. <krotoff@boy.nmd.msu.ru> writes:
  21.  
  22. |> I have a confusion with initialization of class objects.
  23. |> Example:
  24.  
  25. |> class C {
  26. |>  public:
  27. |>     C(int i);
  28. |> };
  29.  
  30. |> class D {
  31. |>  public:
  32. |>     D(C c);
  33. |> };
  34.  
  35. |> D d = 1;
  36.  
  37. |> void f()
  38. |> {
  39. |>     D d = 1;
  40. |> }
  41.  
  42. |> I assume, that both initializations are wrong, since they require sequence
  43. |> of two user-defined conversions. But some compilers disaggre ;-)
  44.  
  45. Correct.  This is a difference in the initialization formats: if you
  46. had written `D d( 1 )', they would be legal.  Apparently, some
  47. compilers are not making the distinction.  (The compiler is allowed to
  48. optimize out the temporary and the call to the copy constructor, but
  49. this is just an optimization, and is not allowed to affect the
  50. legality of the program.)
  51.  
  52. |> Boralnd c++ 4.0:    cannot convert "int" to "D"
  53. |> g++ 2.7.2:        no matching funcion for call to "D::D(int)"
  54. |> MS VC 4.0:        no errors
  55. |> Watcom 10.0:        no errors
  56.  
  57. |> As seems to me only Borland gives adequate diagnostics.
  58.  
  59. |> Who is right ? 
  60.  
  61. Borland and g++.  While I find the g++ diagnostics acceptable, it's
  62. true that the Borland one is clearer, particularly for a neophyte.
  63.  
  64. --
  65. James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
  66. GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
  67. Conseils, Θtudes et rΘalisations en logiciel orientΘ objet --
  68.                 -- A la recherche d'une activitΘ dans une region francophone
  69. ---
  70. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  71.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  72.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  73.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  74.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  75. ]
  76.